
let uploadApi = {
    // 上传单张图片
    uploadImage(callback: any) {
        let token: string = uni.getStorageSync('access_token');
        uni.chooseImage({
            success: (chooseImageRes) => {
                uni.showLoading({
                    title: 'loading...'
                });
                const tempFilePaths = chooseImageRes.tempFilePaths;
                uni.uploadFile({
                    url: `/api${import.meta.env.VITE_UPLOAD_URL}`, //仅为示例，非真实的接口地址
                    filePath: tempFilePaths[0],
                    fileType: 'image',
                    name: 'file',
                    header: {
                        'Authorization': `Bearer ${token}`,
                        'CLIENT-TOC': 'Y',
                        'SKIP_TOKEN': 'Y',
                        'TENANT-ID': uni.getStorageSync('TENANT-ID')
                    },
                    success: (uploadFileRes) => {
                        callback(JSON.parse(uploadFileRes.data).data.outUrl)
                    },
                    fail: (error) => {
                        console.log(error)
                    },
                    complete: () => {
                        setTimeout(function () {
                            uni.hideLoading();
                        }, 250);
                    }
                });
            }
        });
    }
}
export default uploadApi;